 package component
{
	import component.AdvancedImageViewer;
	
	import flash.display.StageDisplayState;
	import flash.events.Event;
	import flash.utils.ByteArray;
	
	import mx.containers.VBox;
	
	

	public class PhcVideocodageUI  extends VBox
	{
	
		public var _imageViewer:AdvancedImageViewer;
		public static var zoomEnabled:Boolean = true;
		private var _image:ByteArray;
		private var enabledUI:Boolean = true;
		public function setImagePosition(page:int,pagePosition:String,xp:int,yp:int):void
		{
			this._imageViewer.setImagePosition(page,pagePosition,xp,yp);
		}
		
			public function get image():ByteArray
		{
			return _image;
		}

		public function set image(value:ByteArray):void
		{
			_image = value;
		}


		
		 public function resetZoom():void
		{
			this._imageViewer.resetZoom();
		}
		
		private function toogleFullScreen(event:Event):void{
			switch(this.stage.displayState){
				case StageDisplayState.FULL_SCREEN:
					this.stage.displayState=StageDisplayState.NORMAL;
					break;
				default:
					this.stage.displayState=StageDisplayState.FULL_SCREEN;
					break;
			}
		}
		
		private function keyboard1Command(charCode:uint):void{
			if(charCode > 48 && charCode < 58){
					var q:uint=charCode-48;
					this._imageViewer.gotoQuadrantCommand(q);
					return;
				}
				switch(charCode){
					case 43:
						this._imageViewer.zoomIncrementCommand();
						break;
					case 45:
						this._imageViewer.zoomDecrementCommand();
						break;	
					case 97:
					this._imageViewer.resetAlignement();
						//this._imageViewer.incModeAlignementCommand();
						break;
					case 121:
					   zoomEnabled =true;
					   break;
					case 122:
						//this._imageViewer.zoomResetCommand();
						zoomEnabled =false;
						break;
					/* case 109:
						this._imageViewer.posAutoToogleCommand();
						break; */
					case 117:
						this._imageViewer.modeDecoupeToggleCommand();
						break;
					case 120:
						this._imageViewer.incDecoupeModeCommand();
						break;
					case 103:
						this._imageViewer.resetDecoupeCommand();
						break;
				}
		}
		
		
		private function keyboard2Command(charCode:uint):void{
			switch(charCode){
				    case 36:
				        this._imageViewer.changeCoordVisibility();
				        break;
					case 77:
					 	this._imageViewer.showAideCommand();
					 	break;
					case 71:
						this._imageViewer.multiPageToogle();
						break;
					case 89:
						this._imageViewer.toolBarToogle();
						break;
					case 88:
						this._imageViewer.rotateCommand();
						break;
					
			
				}
		}
		
		 public function keyboardCommand(charSet:int,charCode:uint):void{
			if(!enabledPhc)
			     return;
			     
			if(charSet==1){
				 keyboard1Command(charCode);
			}
			if(charSet==2){
				 keyboard2Command(charCode);
			}
		}
        
        public function get enabledPhc():Boolean
	    {
	    	return enabledUI;
	    }
	    
		   public function set enabledPhc(value:Boolean):void
	    {
	    	
	    	enabledUI = value;
	    	focusEnabled = value;
	    } 
	    
		  public function pageUp():void{
			this._imageViewer.pageUpCommand();
		}

		  public function pageDown():void{
			this._imageViewer.pageDownCommand();
		}

		  public function pageBegin():void{
			this._imageViewer.pageBeginCommand();
		}

		  public function pageEnd():void{
			this._imageViewer.pageEndCommand();
		} 
		
		
		
			
		/* override protected function createChildren():void{
			super.createChildren();
			this.enabled=true;	
			var conf:PhcImageConfiguration = this.configuration as PhcImageConfiguration;
			this._imageViewer=new AdvancedImageViewer();	
			
			this.addChild(this._imageViewer);
			if(conf.inMasterDetail)
			{
				callLater(initImage);
			}
		} */
		
		
		 /* protected function initializationComplete():void{
			var conf:PhcImageConfiguration = this.configuration as PhcImageConfiguration;	
			this._imageViewer.height=conf.heigth;
			this._imageViewer.width=conf.width;
			this._imageViewer.containerDimension(conf.width,conf.heigth);	
			//this._imageViewer.modePosAuto=conf.modePosAuto;
			this._imageViewer.modeDecoupeImageEnabled=conf.modeDecoupeImageEnabled;
			this._imageViewer.initModeAlignement(conf.modeAlignement);
			this._imageViewer.decoupeMode=conf.decoupeMode;
			this._imageViewer.tabEnabled=false;
			this._imageViewer.toolBarVisible=conf.toolBarVisible;
			this._imageViewer.allPropertyIsSet();
			
		} */
				public function initImage() :void
			{		 
				    this._imageViewer.image.setBytes(null);
			}

		public function PhcVideocodageUI()
		{
			super();
		}
	}
}